package com.sh.test;

public class MaxRotatedValue {


    public static String rotateRight(String numStr, int k) {
        int length = numStr.length();
        k = k % length;
        return numStr.substring(length - k) + numStr.substring(0, length - k);
    }


    public static long findMaxRotatedValue(long num) {
        String numStr = Long.toString(num);
        int length = numStr.length();
        long maxValue = num;

        for (int i = 1; i < length; i++) {
            String rotatedStr = rotateRight(numStr, i);
            long rotatedValue = Long.parseLong(rotatedStr);
            if (rotatedValue > maxValue) {
                maxValue = rotatedValue;
            }
        }

        return maxValue;
    }

    public static void main(String[] args) {
        long num = 9527L;
        long maxRotated = findMaxRotatedValue(num);
        System.out.println("数字 " + num + " 通过循环右移操作能达到的最大值是: " + maxRotated);
    }
}